package http

type ResponseLine struct {
	HttpVersion string
	StatusCode  string
	StatusDesc  string
}

type Response struct {
	ResponseLine ResponseLine
	Header       Header
	Body         Body
}

func (this *ResponseLine) Encode() []byte {
	str := this.HttpVersion
	str += SPACE
	str += this.StatusCode
	str += SPACE
	str += this.StatusDesc
	str += CRTL

	return []byte(str)
}

func (this *Response) Encode() []byte {
	responseEncodeBytes := make([]byte, 0)
	responseEncodeBytes = append(responseEncodeBytes, this.ResponseLine.Encode()...)
	responseEncodeBytes = append(responseEncodeBytes, this.Header.Encode()...)
	length := this.Header.GetContentLength()
	if length >= 0 {
		data := make([]byte, length)
		this.Body.Read(data)
		responseEncodeBytes = append(responseEncodeBytes, data...)
	}

	return responseEncodeBytes
}
func CreateResponse() *Response {
	res := &Response{
		Header: Header{
			header: map[string][]string{},
		},
	}

	return res
}
